package LC;

/**
 * @ClassName LC124
 * @Description: TODO
 * @Author hl
 * @Date 2020/5/29
 * @Version V1.0
 **/
public class LC124 {
    int result=Integer.MIN_VALUE;

    public int maxPathSum(TreeNode root) {
       seach(root);
       return  result;
    }

    public int seach(TreeNode root){
        if(root==null){
            return  0;
        }
        int left=Math.max(seach(root.left),0);
        int right=Math.max(seach(root.right),0);
        //记录包含当前节点的最大路径和
        int temp=root.val+left+right;
        result=Math.max(result,temp);
        //返回以当前节点为起始点的最大路径和
        return  root.val+Math.max(left,right);
    }
}
